package week_home_work02;

import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/23
 */
public class Demo71 {
    public static void main(String[] args) {
        //实现一个程序，计算1到n之间的所有质数并统计它们的个数。
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数字:");
        int num = sc.nextInt();
        int count = 0;
        for (int i = 2; i <= num ; i++) {
            boolean flag  =true;
            for (int j = 2; j < Math.sqrt(i) ; j++) {
                if (i % j==0){
                    flag  =false;
                    break;
                }
            }
            if (flag){
                System.out.print(i+"\t");
                count++;
            }
        }
        System.out.println();
        System.out.println("count="+count);
    }
}
